package com.fuhao.service.impl;

import com.fuhao.dao.UserMapper;
import com.fuhao.model.Mail;
import com.fuhao.model.User;
import com.fuhao.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service("queue")
public class QueueProductServiceImpl implements ProductService {
    @Autowired
    @Qualifier("jmsTemplate")
    private JmsTemplate jmsTemplate;

    @Autowired
    private UserMapper userMapper;

    public void setJmsTemplate(JmsTemplate jmsTemplate) {
        this.jmsTemplate = jmsTemplate;
    }

//    @Transactional
    public void sendMail(Mail mail) {
        jmsTemplate.convertAndSend(mail);
    }

    @Transactional
    public void sendUser(User user) {
        User user1 = new User();
        user1.setUsername("rich");
        user1.setAge(12);
        user1.setSex(1);
        userMapper.insert(user1);
        //int i = 1/0;
        jmsTemplate.convertAndSend(user);



    }

    @Transactional
    public void saveUser(User user){
        userMapper.insert(user);
    }
}
